package com.example.bijiabao.controller;

import com.example.bijiabao.entity.user;
import com.example.bijiabao.services.usercenterServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/usercenter")
public class usercenterController {

    @Autowired
    private usercenterServices usercenterServices;
    //个人中心获得用户信息
    @GetMapping("/getInfo")
    public user GetUser(@RequestParam("userName") String userName){
        user user = usercenterServices.SelectUser(userName);
        return user;
    }
    @PostMapping("/update")
    public Integer UpdateUser(@RequestBody user user){
        return usercenterServices.UpdateUser(user);
    }

    @GetMapping("/reset")
    public Integer ResetPassword(@RequestParam("userOldPassword") String OldPassword,@RequestParam("usersetpassword") String setpassword,@RequestParam("userName") String userName){
        String checkpassword=usercenterServices.checkPassword(userName);
        Integer result=100;
        if (checkpassword==OldPassword){
            result= usercenterServices.ResetUserPassWord(userName,setpassword);
        }
        return result;
    }

}
